package packet.player;

import java.nio.ByteBuffer;

import packet.GCOperationResultResp;
import packet.Packet;
import packet.PacketConstant;
import player.Player;

public class CGLoginAsk extends Packet 
{
	public int execute(Player player, int moduleFlag) 
	{
		if (! isCallerAllowable(moduleFlag))
		{
			return PacketConstant.PACKET_EXCUTE_NOALLOW;
		}
		
		GCOperationResultResp operationResult = new GCOperationResultResp(getSN(), 0);
		player.sendPacket(operationResult);
		
		return 0;
	}
	
	public int readFromBuffer(ByteBuffer buffer)
	{
		int mark = buffer.position();
		
		super.readFromBuffer(buffer);
		
		platformID = buffer.getInt(); 
		
		int length = buffer.getInt(); 
		byte nameByte[] = new byte[length];
		buffer.get(nameByte);
		name = new String(nameByte); 
		
		length = buffer.getInt(); 
		byte tokenByte[] = new byte[length];
		buffer.get(tokenByte);
		loginToken = new String(tokenByte); 
		
		return (buffer.position() - mark);
	}
	
	public String getPacketName()
	{
		return "CGLoginAsk";
	}
	
	public String getPacketDetail()
	{
		return String.format("platformID=%d,name=%s,logintoken=%s", platformID, name, loginToken);
	}
	
	public int getPacketSize()
	{
		return super.getPacketSize() + 4 + 4 + 4; 
	}
	
	public int getCallerAllowable()
	{
		return PacketConstant.PACKET_ALLOWABLE_LOGIN;
	} 
	
	private int    platformID;
	private String name;
	private String loginToken;  
}
